#include "ObjectsMapper.h"
#include "../DataSourceInstance.h"
#include "../common/YXMySQL.h"
#include "../common/YXString.h"

MYSQLResult* insertObject(char* name, char* type, char* parentPath, long long size, long long lastModifiedTime) {
    static char* sqlTemplate = "insert into objects (name, type, size, last_modified_time, parent) values ('%s', '%s', %lld, %lld, '%s')";
    char* sql = yxString_printf(sqlTemplate, name, type, size, lastModifiedTime, parentPath);

    Connection* connection = getConnection(dataSource);
    MYSQLResult* result = exceuteQuery(connection, sql);
    returnConnection(dataSource, connection);

    return result;
}

MYSQLResult *selectObjects(int lastId, char *parentPath) {
    static char *sqlTemplate = "select * from objects where id > '%d' and parent = '%s'";
    char        *sql         = yxString_printf(sqlTemplate, lastId, parentPath);

    Connection  *connection = getConnection(dataSource);
    MYSQLResult *result     = exceuteQuery(connection, sql);
    returnConnection(dataSource, connection);

    return result;
}
